package com.gzxw.mogublog.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzxw.mogublog.commons.entity.Subject;
import com.gzxw.mogublog.utils.R;
import com.gzxw.mogublog.xo.service.SubjectService;
import com.gzxw.mogublog.xo.vo.SubjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    // 1.获取专题列表
    @PostMapping("/getList")
    public R getList(@RequestBody SubjectVO subjectVO) {

       IPage<Subject> pageList =  subjectService.getList(subjectVO);
        Map<String ,Object> map = new HashMap<>();
        map.put("records",pageList.getRecords());
        map.put("total",pageList.getTotal());
        map.put("size",pageList.getSize());
        map.put("current",pageList.getCurrent());

        return R.success("返回成功",map);
    }

    // 2.添加专题
    @PostMapping("/add")
    public R add(@RequestBody SubjectVO subjectVO) {

       String message = subjectService.add(subjectVO);

       return R.success("200",message);
    }


    // 3.编辑专题
    @PostMapping("/edit")
    public R edit(@RequestBody SubjectVO subjectVO) {

        String message = subjectService.edit(subjectVO);

        return R.success("200",message);
    }


    // 4.批量删除专题
    @PostMapping("/deleteBatch")
    public R deleteBatch(@RequestBody List<SubjectVO> subjectVOList) {

       String message =  subjectService.deleteBatch(subjectVOList);

       return R.success("200",message);
    }

}
